#include "PolylineCollisionObject.h"
#include "il_assert.h"
#include "Iw2D.h"

void PolylineCollisionObject::Load( const CIwFVec2& pos, const char* image )
{
	m_sprite.Load( image );
	m_pos = pos;
	m_num_points = 0;
}

void PolylineCollisionObject::AddPoint( CIwFVec2 point )
{
	IL_ASSERT( m_num_points < MAX_NUM_POINTS, "maximum number of points reached" );
	
	m_points[m_num_points] = m_pos + point;
	
	++m_num_points;
}

void PolylineCollisionObject::Unload()
{
	m_sprite.Unload();
}

void PolylineCollisionObject::Draw( )
{
	CIwSVec2 pos( (int) m_pos.x, (int) m_pos.y );
	m_sprite.Draw( pos );
	
	/*
	// draw debug lines
	for( int i = 0; i < m_num_points -1; ++i ) {
		Iw2DDrawLine( 
			CIwSVec2( (int)m_points[i].x, (int)m_points[i].y ), 
            CIwSVec2( (int)m_points[i+1].x, (int)m_points[i+1].y ) ); 
    }*/
}

const CIwFVec2* PolylineCollisionObject::GetCollisionPoints() const
{
	return &(m_points[0]);
}

int PolylineCollisionObject::GetNumCollisionPoints() const
{
	return m_num_points;
}

CIwFVec2 PolylineCollisionObject::GetPos() const
{
	return m_pos;
}

float PolylineCollisionObject::GetWidth() const
{
	return m_sprite.GetWidth();
}

float PolylineCollisionObject::GetHeight() const
{
	return m_sprite.GetHeight();
}